import React, {Component} from 'react'
import config from './config.json';
import styles from './Greeter.css';//导入
import myless from './Greeter.less';
import 'isomorphic-fetch'

class Greeter extends Component{
	constructor(props){
		super(props);
		this.state = {linked:false};
		this.handleClick = this.handleClick.bind(this);//绑定this作用域
	}
	handleClick() {
        this.setState({linked:!this.state.liked});
        let _this = this;
        fetch(this.props.source)
        .then(response=>response.json())
        .then(data=>data.headers.Host)
        .then(data=><b>{data}</b>)
        .then(data=>_this.setState({aa:data}))
        
    }
  render() {
    return (
      <div className={styles.root}>
        {config.greetText}<h1>{this.props.name}</h1>
       {
       	React.Children.map(this.props.children,child=> <li>{child}</li> )
       }
       {this.state.linked? this.state.aa:<div>为加载</div>}
        <input type="text" ref="myTextInput" />
        <input type="button" value="文本获取焦点" onClick={this.handleClick} />
      </div>
    );
  }
}

export default Greeter